//
//  SLMapViewController.m
//  StarLight
//
//  Created by Duke.wu on 16/5/18.
//  Copyright © 2016年 Duke.Wu. All rights reserved.
//

#import "SLMapViewController.h"
#import <QMapKit/QMapKit.h>
#import "PoiAnnotation.h"





@interface SLMapViewController ()<QMapViewDelegate>

@property (nonatomic, strong) QMapView *mapView;

@property (nonatomic, assign) CLLocationCoordinate2D coordi;

@end

@implementation SLMapViewController

- (void)viewDidLoad {
    [super viewDidLoad];
  self.mapView = [[QMapView alloc] initWithFrame:self.view.bounds];
  self.mapView.delegate = self;
//  UIImageView *current = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"currentLocation"]];
  [self.view addSubview:self.mapView];
//  [self.view addSubview:current];
//  
//  [current mas_makeConstraints:^(MASConstraintMaker *make) {
//    make.center.equalTo(self.view);
//    make.size.mas_equalTo(CGSizeMake(16, 18));
//  }];
  
  @weakify(self)
  dispatch_async(dispatch_get_main_queue(), ^{
    @strongify(self);
    [self.mapView setCenterCoordinate:self.coordi];
  });
    
}


- (void)viewWillAppear:(BOOL)animated{
  [super viewWillAppear:animated];
  [self.navigationController setNavigationBarHidden:NO animated:YES];
  QPointAnnotation *yinke = [[QPointAnnotation alloc] init];
  yinke.coordinate = self.coordi;
  [self.mapView addAnnotation:yinke];
//  self.mapView.zoomLevel = 12.1;
}


- (void)locationWithLon:(float)lon lat:(float)lat{
  self.coordi = CLLocationCoordinate2DMake(lat, lon);
}

- (void)mapView:(QMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
  
}


-(QAnnotationView *)mapView:(QMapView *)mapView
          viewForAnnotation:(id<QAnnotation>)annotation {
  static NSString *pointReuseIndentifier = @"pointReuseIdentifier";
  
  if ([annotation isKindOfClass:[QPointAnnotation class]]) {
    //添加默认pinAnnotation
    QPinAnnotationView *annotationView = (QPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndentifier];
    if (annotationView == nil) {
      annotationView = [[QPinAnnotationView alloc]
                        initWithAnnotation:annotation
                        reuseIdentifier:pointReuseIndentifier];
      annotationView.draggable = NO;
      UIImage *image1 = [UIImage imageNamed:@"currentLocation"];
      annotationView.image = image1;
      return annotationView;
    }
  }
  return nil;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
